<template>
  <div class="insalegoods">
    <div class="head">
      <el-row>
        <el-col :span="6">
          <el-input  @keyup.enter.native="search_key(search)" v-model="search" placeholder="输入商品编号查询" prefix-icon="el-icon-search" clearable></el-input>
        </el-col>
        <el-col :span="2">
          <el-button type="primary" @click="search_key(search)">查询</el-button>
        </el-col>
        <el-col :span="6">
          <el-input v-model="input2" placeholder="商品分类" prefix-icon="el-icon-search" clearable></el-input>
        </el-col>
        <el-col :span="2">
          <el-button type="primary">查询</el-button>
        </el-col>
      </el-row>
    </div>
    <div class="list_content">
      <el-table
        :data="tableData"
        border
      >
        <el-table-column prop="date" label="序号" width="150"></el-table-column>
        <el-table-column prop="name" label="商品编号" width="120"></el-table-column>
        <el-table-column prop="province" label="商品名称" width="120"></el-table-column>
        <el-table-column prop="city" label="缩略图" width="120"></el-table-column>
        <el-table-column prop="address" label="进货价" width="300"></el-table-column>
        <el-table-column prop="zip" label="零售价" width="120"></el-table-column>
        <el-table-column prop="zip" label="销售类型" width="120"></el-table-column>
        <el-table-column prop="zip" label="商品分类" width="120"></el-table-column>
        <el-table-column prop="zip" label="销量" width="120"></el-table-column>
        <el-table-column prop="zip" label="库存" width="120"></el-table-column>
        <el-table-column fixed="right" prop="zip" label="操作" width="120">
          <template slot-scope="scope">
            <a href="javascript:;" @click="goInfo(scope.$index, scope.row)" size="small">查看</a>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      search: "",
      input2: "",
      schfilter: "",
      tableData: [
        {
          date: "10069",
          name: "刘艹艹",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1518 弄",
          zip: 200333
        },
        {
          date: "488965",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1517 弄",
          zip: 200333
        },
        {
          date: "998964512",
          name: "成欧共",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1517 弄",
          zip: 200333
        },
        {
          date: "881628",
          name: "张天福",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1517 弄",
          zip: 200333
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1517 弄",
          zip: 200333
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1517 弄",
          zip: 200333
        },
        {
          date: "2016-05-04",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1517 弄",
          zip: 200333
        },
        {
          date: "2016-05-01",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1519 弄",
          zip: 200333
        },
        {
          date: "2016-05-03",
          name: "王小虎",
          province: "上海",
          city: "普陀区",
          address: "上海市普陀区金沙江路 1516 弄",
          zip: 200333
        }
      ]
    };
  },
  methods: {
    goInfo(index, row) {
      //点击进去详情
      console.log(index, row, row.date);
      this.$router.push({ name: "goodsinfo", params: { id: index } });
    },
    search_key(search) {
      // 搜索商品编号及商品名称
      if (search == "") {
        //  如果搜索为空，就再次调用一下后台最初传递过来的 表单 方法： this.getdata()
        return;
      } else {
        var newslist = this.tableData.filter(item => {
          //搜索商品名称
          if (item.name.includes(this.search)) {
            return item;
          }
          //搜索商品编号
          if (item.date.includes(this.search)) {
            return item;
          }
        });
        this.tableData = newslist;
      }
    },
    test(){
      console.log("测试")
    }
  },
  created() {}
};
</script>
<style lang="scss" scoped>
body {
  margin: 0;
}
.insalegoods {
  padding: 20px 10px;
  min-height: 500px;
  background: #fff;
  border-radius: 15px;
  .el-input,
  button {
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
  }
}

.list_content {
  margin-top: 20px;
}
</style>